﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationHistory.aspx.cs" Inherits="CRMWeb.Pages.ApplicationHistory" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Application History</title>
</head>
<body>
    <form id="form1" runat="server">
        <div data-options="region:'center'" style="height: auto;">
            <input type="hidden" runat="server" id="hdnUserName" />
            <table cellspacing="0" class="history_table" cellpadding="0" border="0">
                <tr>
                    <td style="width: 39%; vertical-align: top">
                        <table id="dgApplicationHistory" style="width: auto" class="esyui-datagrid"
                            toolbar="#toolbarApplicationHistory" pagination="true" data-options="pageSize:10"
                            rownumbers="true" fitcolumns="true" singleselect="true" autorowheight="true">
                            <thead>
                                <tr>
                                    <th field="HistoryID" hidden="true">HistoryID</th>
                                    <th field="HistoryDate" data-options="formatter:formatHistoryDate" width="30">Date</th>
                                    <th field="HistoryTime" data-options="formatter:formatHistoryTime" width="20">Time</th>
                                    <th field="Action" width="60">Action</th>
                                    <th field="Operator" width="20">Operator</th>
                                </tr>
                            </thead>
                        </table>
                        <div id="toolbarApplicationHistory">
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newApplicationHistory()">New</a>
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editApplicationHistory('')">Edit</a>
                            <input id="chkFieldChanged" type="checkbox" title="Field Changed" />Field Changed
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" plain="true" onclick="allApplicationHistory()">ALL</a>
                        </div>
                    </td>
                    <td style="width: 58%; vertical-align: top">
                        <div id="divHistoryPreview" class="easyui-panel" title="History Preview" style="height: 530px; padding: 5px;">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#dgApplicationHistory').datagrid({
                    url: '/WebServices/History.ashx?method=SelectAllHistoryNotFieldChange&historyType=Application&ID=' + getQuerystring('app_id', ''),
                    onDblClickRow: function (index, rowdata) {
                        editApplicationHistory(rowdata.HistoryID);
                    },
                    onClickRow: function (index, rowdata) {
                        if (rowdata.Description == null)
                            $('#divHistoryPreview').html('');
                        else {
                            var data = decodeURIComponent(rowdata.Description);
                            if (rowdata.Action == 'CreditCheck') {
                                var XMLFileName = data.split(":");
                                data = XMLFileName[0] + ' :' + "<a href='/Pages/Application/VedaResponseData/" + XMLFileName[1] + "' target='_blank' style='cursor:pointer'>" + XMLFileName[1] + "</a>";
                                $('#divHistoryPreview').html(data);
                            }
                            else {
                                $('#divHistoryPreview').html(data);
                            }
                        }
                    },
                    onLoadSuccess: function (data) {
                        setHeight();
                    },
                    onSelect: function (rowIndex, rowData) {
                        document.onkeydown = function chekKey(e) {
                            e = e || window.event;
                            if (e.keyCode == '38') // up arrow
                            {
                                if (rowIndex == 0)
                                    $('#dgApplicationHistory').datagrid('selectRow', 4);
                                else
                                    $('#dgApplicationHistory').datagrid('selectRow', rowIndex - 1);
                            }
                            else if (e.keyCode == '40') // down arrow
                            {
                                if (rowIndex == 29)
                                    $('#dgApplicationHistory').datagrid('selectRow', 0);
                                else
                                    $('#dgApplicationHistory').datagrid('selectRow', rowIndex + 1);
                            }
                        }
                    }
                });
                $('#chkFieldChanged').on('change', function () {
                    if (!this.checked) {
                        $('#dgApplicationHistory').datagrid({
                            url: '/WebServices/History.ashx?method=SelectAllHistoryNotFieldChange&historyType=Application&ID=' + getQuerystring('app_id', '')
                        });
                    }
                    else {
                        $('#dgApplicationHistory').datagrid({
                            url: '/WebServices/History.ashx?method=SelectAllHistoryByType&historyType=Application&ID=' + getQuerystring('app_id', '')
                        });
                    }
                });
            });

            function newApplicationHistory() {
                popupWinCenter('/Pages/History.aspx?type=Application&Operation=new&app_id=' + getQuerystring('app_id', ''), 'New Application History', 650, 625);
            }

            function editApplicationHistory(history_id) {
                if (history_id == '') {
                    var row = $('#dgApplicationHistory').datagrid('getSelected');
                    history_id = row.HistoryID;
                }
                popupWinCenter('/Pages/History.aspx?type=Application&Operation=edit&historyid=' + history_id + '&app_id=' + getQuerystring('app_id', ''), 'Edit Application History', 650, 620);
            }

            function allApplicationHistory() {
                window.open('/Pages/AllHistory.aspx?type=Application&app_id=' + getQuerystring('app_id', ''), '_blank');
            }

            function popupWinCenter(URL, title, w, h) {
                var left = (screen.width / 2) - (w / 2);
                var top = (screen.height / 2) - (h / 2);
                var strfeatures = 'width=' + w + ', height= ' + h + ', top=' + top + ',left=' + left;
                var newWin = window.open(URL, title, strfeatures);
                newWin.onload = function () { window.focus(); }
                newWin.onunload = function () { $('#dgApplicationHistory').datagrid('reload'); }
            }

            function formatHistoryDate(value, row) {
                if (value == null)
                    return '';
                var date = new Date(value);
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                var month = '';
                switch (m) {
                    case 1:
                        month = 'Jan';
                        break;
                    case 2:
                        month = 'Feb';
                        break;
                    case 3:
                        month = 'Mar';
                        break;
                    case 4:
                        month = 'Apr';
                        break;
                    case 5:
                        month = 'May';
                        break;
                    case 6:
                        month = 'Jun';
                        break;
                    case 7:
                        month = 'Jul';
                        break;
                    case 8:
                        month = 'Aug';
                        break;
                    case 9:
                        month = 'Sep';
                        break;
                    case 10:
                        month = 'Oct';
                        break;
                    case 11:
                        month = 'Nov';
                        break;
                    case 12:
                        month = 'Dec';
                        break;
                }
                var d = date.getDate();
                return (d < 10 ? ('0' + d) : d) + ' ' + month + ' ' + y;
            }

            function formatHistoryTime(value, row) {
                var hourEnd = value.indexOf(':');
                var H = +value.substr(0, hourEnd);
                var minutes = value.substring(3, 5);
                var ampm = '';
                if (H == 00) {
                    value = '00:' + minutes + 'AM';
                }
                else if (H == 12) {
                    value = '12:' + minutes + 'PM';
                }
                else {
                    var h = H % 12 || 12;
                    ampm = H < 12 ? 'AM' : 'PM';
                    value = h + value.substr(hourEnd, 3) + ampm;
                }
                return value;
            }

        </script>
    </form>
</body>
</html>

